import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')
df = pd.read_csv('14. Ground Floor vs InsideTemperature.csv')
df.head()
Date | InsideTemperature | GroundFloor | Unnamed: 3 | Unnamed: 4 | |
---|---|---|---|---|---|
0 | 6/16/2021 0:00 | 27.430000 | 3.389676 | NaN | NaN |
1 | 6/17/2021 0:00 | 28.200000 | 6.925224 | NaN | NaN |
2 | 6/18/2021 0:00 | 29.063333 | 6.934230 | NaN | NaN |
3 | 6/19/2021 0:00 | 29.127500 | 6.912297 | NaN | NaN |
4 | 6/20/2021 0:00 | 29.230833 | 6.904380 | NaN | NaN |
df.dtypes
Date object InsideTemperature float64 GroundFloor float64 Unnamed: 3 float64 Unnamed: 4 object dtype: object
df['Date'] = pd.to_datetime(df['Date'])
df.head()
Date | InsideTemperature | GroundFloor | Unnamed: 3 | Unnamed: 4 | |
---|---|---|---|---|---|
0 | 2021-06-16 | 27.430000 | 3.389676 | NaN | NaN |
1 | 2021-06-17 | 28.200000 | 6.925224 | NaN | NaN |
2 | 2021-06-18 | 29.063333 | 6.934230 | NaN | NaN |
3 | 2021-06-19 | 29.127500 | 6.912297 | NaN | NaN |
4 | 2021-06-20 | 29.230833 | 6.904380 | NaN | NaN |
df['month'] = df['Date'].dt.month
df.head()
Date | InsideTemperature | GroundFloor | Unnamed: 3 | Unnamed: 4 | month | |
---|---|---|---|---|---|---|
0 | 2021-06-16 | 27.430000 | 3.389676 | NaN | NaN | 6 |
1 | 2021-06-17 | 28.200000 | 6.925224 | NaN | NaN | 6 |
2 | 2021-06-18 | 29.063333 | 6.934230 | NaN | NaN | 6 |
3 | 2021-06-19 | 29.127500 | 6.912297 | NaN | NaN | 6 |
4 | 2021-06-20 | 29.230833 | 6.904380 | NaN | NaN | 6 |
df['week'] = df.Date.dt.strftime('%W')
df1 = df.groupby('month',as_index=False).mean()
df2 = df.groupby('week',as_index=False).mean()
fig, ax = plt.subplots(figsize=(20,10))
ax2 = ax.twinx()
ax.set_title('Avg Monthly Temperature and Energy Consumption', fontsize = 20)
ax.set_xlabel('Month')
ax.plot(df1['month'], df1['InsideTemperature'], color='green', marker='x')
ax2.plot(df1['month'], df1['GroundFloor'], color='red', marker='o')
ax.set_ylabel('Inside Temperature [°C]')
ax2.set_ylabel('Thermal energy for heating & cooling [kwh]')
ax.legend(['Inside Temperature [°C]'], loc='upper left')
ax2.legend(['Thermal energy for heating & cooling [kwh]'], loc='upper right')
#ax.set_xticks(df['Date'].dt.date)
#ax.set_xticklabels(df['Date'].dt.year, rotation=90)
plt.show()
fig, ax = plt.subplots(figsize=(20,10) )
plt.rcParams['figure.dpi'] = 2000
ax2 = ax.twinx()
ax.set_title('Avg Weekly Temperature and Energy Consumption', fontsize = 20)
ax.set_xlabel('Week')
ax.plot(df2['week'], df2['InsideTemperature'], color='green', marker='x')
df2.plot(x='week', y='GroundFloor', kind='bar', ax=ax, alpha=0.4, color='red')
ax.set_ylabel('Inside Temperature [°C]', fontsize = 10)
ax2.set_ylabel('Thermal energy for heating & cooling [kwh]',fontsize = 10)
ax.legend(['Inside Temperature [°C]'], loc='upper left',fontsize = 10)
plt.show()